<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title></title>
    <script src="js/mui.min.js"></script>
    <link href="css/mui.min.css" rel="stylesheet"/>
	<script>

	</script>
</head>
<body>
	<header class="mui-bar mui-bar-nav">
		<a class="mui-icon mui-action-menu mui-icon-arrowleft mui-pull-left" onclick="mui.back()"></a>
		<h1 class="mui-title">设置</h1>
		<a class="mui-icon mui-action-menu mui-pull-right" onclick="open_login()">登录</a>
	</header>
	<div class="mui-content">
	</div>
	
	<div class="mui-input-row">
	    <label>班级号</label>
	    <input id="bh" type="text" class="mui-input-clear" placeholder="班级号">
	</div>
	<button class="mui-btn mui-btn-block mui-btn-blue" id="s_h" onclick="s_h()">保存</button>
	<hr />
	<div class="mui-input-row">
	    <label>任务服务器</label>
	    <input id="rwurl" type="text" class="mui-input-clear" placeholder="服务器">
	</div>
	
	<div class="mui-input-row">
	    <label>语音服务器</label>
	    <input id="yyurl" type="text" class="mui-input-clear" placeholder="服务器">
	</div>
	<button class="mui-btn mui-btn-block mui-btn-blue" id="s_s" onclick="s_s()">保存</button>
	<script type="text/javascript" charset="utf-8">
		function open_login(){
			mui.openWindow({
					url:'login.html',
					id:'login',
			})
		}
	  	mui.init();
		mui.plusReady(function () {
			document.getElementById("rwurl").value = plus.storage.getItem("rw_server");
			document.getElementById("yyurl").value = plus.storage.getItem("yy_server");
			document.getElementById("bh").value = plus.storage.getItem("class_id");
		})
		document.addEventListener("plusready", function() {
			// 页面加载完成后自动执行

		});
		
		function s_h(){
			var bh = document.getElementById("bh").value;
			var url = plus.storage.getItem("rw_server")+"setclassid"
			if(bh == ""){
				mui.toast("班级号不能为空");
				return;
			}
			fetch(url, {
			    method: "post",
			    headers: {
			        "Content-Type": "application/json"
			    },
			    body: JSON.stringify({
			        "user_id": plus.storage.getItem("user_id"),
			        "password": plus.storage.getItem("password"),
					"class": bh
			    })
			})
			.then(function (response) {
			    return response.text();
			})
			.then(function (data) {
				mui.toast(data);
				plus.storage.setItem("class_id", String(bh))
			})
			.catch(function (error) {
			    console.log(error);
			});
		}
		
		function s_s(){
			var rwurl = document.getElementById("rwurl").value;
			var yyurl = document.getElementById("yyurl").value;
			if(rwurl == "" || yyurl == ""){
				mui.toast("服务器不能为空");
				return;
			}
			plus.storage.setItem("rw_server",String(rwurl));
			plus.storage.setItem("yy_server",String(yyurl));
			mui.toast("保存成功");
		}
	</script>
</body>
</html>